﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Controller;
using System.Data.SqlClient;

namespace QLKS
{
    public partial class FrmRoomType : Form
    {
        Controller_Room cont_room = new Controller_Room();
        public FrmRoomType()
        {
            InitializeComponent();
        }

        private void btn_AddLoaiPhong_Click(object sender, EventArgs e)
        {
            FrmRoomTypeAdd typeadd = new FrmRoomTypeAdd(this);
            typeadd.ShowDialog();
        }
        public void LoadRoom()
        {
            DataTable data = cont_room.ListRoomType().Tables[0];
            dgv_LoaiPhong.DataSource = data;
        }
        private void FrmRoomType_Load(object sender, EventArgs e)
        {
            LoadRoom();
        }

        private void btn_DeleteLoaiPhong_Click(object sender, EventArgs e)
        {
            int r = dgv_LoaiPhong.CurrentRow.Index;
            string roomID = dgv_LoaiPhong.Rows[r].Cells["RoomTypeID"].Value.ToString();
            if (cont_room.Delete_RoomType(roomID))
            {
                MessageBox.Show("Xoá thành công!", "Thông báo");
                LoadRoom();
            }
            else
                MessageBox.Show("Không thể xóa", "Lỗi");
        }

        private void btn_EditLoaiPhong_Click(object sender, EventArgs e)
        {
            DialogResult rs = MessageBox.Show("Bạn có chắc muốn sửa lại?","Thông báo",MessageBoxButtons.OKCancel,MessageBoxIcon.Question);
            if (rs == DialogResult.Cancel)
                return;

            int r = dgv_LoaiPhong.CurrentRow.Index;
            string maPhong =dgv_LoaiPhong.Rows[r].Cells["RoomTypeID"].Value.ToString();
            string tenPhong = dgv_LoaiPhong.Rows[r].Cells["TypeName"].Value.ToString();
            string giaPhong = dgv_LoaiPhong.Rows[r].Cells["Cost"].Value.ToString();
            string mieuta = dgv_LoaiPhong.Rows[r].Cells["Descriptions"].Value.ToString();
            if (cont_room.Update_roomType(maPhong, tenPhong, giaPhong, mieuta))
            {
                MessageBox.Show("Sửa thành công");
                LoadRoom();
            }
            else
                MessageBox.Show("Không sửa đươc");


        }
    }
}
